#!/bin/sh
echo $0 $*
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}

# 修改为直接获取文件夹名称的用法,不同游戏文件名不同
GAMEDIR="/mnt/SDCARD/Ports/iortcw"
# GAMEDIR=${PWD}
echo ==========GAMEDIR is $GAMEDIR
controlfolder="../PortMaster"

source $controlfolder/control.txt
#source $controlfolder/tasksetter

get_controls

# 增加错误输出记录
exec > >(tee "$GAMEDIR/log.txt") 2>&1
cd $GAMEDIR


$ESUDO rm -rf ~/.wolf
ln -sfv $GAMEDIR/conf/.wolf/ ~/
cd $GAMEDIR

$ESUDO chmod 666 /dev/tty1
$ESUDO chmod 666 /dev/uinput


APP_TO_KILL="iowolfsp.aarch64"


$GPTOKEYB $APP_TO_KILL &
SDL_GAMECONTROLLERCONFIG="$sdl_controllerconfig" ./iowolfsp.aarch64 2>&1 | tee $GAMEDIR/log.txt
$ESUDO kill -9 $(pidof gptokeyb)
$ESUDO systemctl restart oga_events &
printf "\033c" > /dev/tty1